<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title>Finalove-App-newFriends</title>
		<link rel="stylesheet" href="../../resource/font/css/font-awesome.min.css">
		<link rel="stylesheet" href="../../resource/css/mint.css">
		<link rel="stylesheet" href="../../resource/css/style.css">
		<script src="../../resource/js/vue.js"></script>
		<script src="../../resource/js/mint.min.js"></script>
		<script src="../../resource/js/jquery.min.js"></script>
		<style type="text/css">
			#main {
				background-color: #F0F0F0;
				overflow-y:auto;
			}
			.ct-box {
				margin-top: 40px;
			}
			.search-result-list {
				margin-top: 15px;
				background-color: #FFF;
				display: none;
			}
			.search-result-list .mint-cell-wrapper img{
				margin-top: 10px;
				margin-right: 15px;
				border-radius: 5px;
			}
			.search-result-list .mint-cell-wrapper{
				margin-bottom: 5px;
			}
			.search-result-list .mint-cell-wrapper .mint-button{
				margin-left: 10px;
			}
			.search-result-list .data-empty {
				padding:30px;
			}
		</style>
	</head>
	<body>
		<div id="main">
			<mt-header fixed title="添加朋友">
				<mt-button icon="back" slot="left" @click="closeView"></mt-button>
			</mt-header>
			<div class="ct-box">
				<div class="search-box">
					<mt-cell>
						<img slot="icon" src="../../resource/icon/find.png" width="24" height="24">
						<mt-field placeholder="搜索用户名/邮箱" v-model="searchText"></mt-field>
						<mt-button type="primary" @click="doSearch">搜索</mt-button>
					</mt-cell>
				</div>
				<div class="search-result-list">
					<mt-cell v-for="item in searchResult" :title="item.user_name" :label="item.nick_name">
						<img slot="icon" :src="item.user_head" width="50" height="50">
						<mt-button type="primary" @click="addApply(item.user_id)">添加</mt-button>
					</mt-cell>
					<p class="text-center data-empty">该用户不存在</p>
				</div>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		var main = new Vue({
			el:"#main",
			data:{
				searchText:"",
				searchResult:""
			},
			mounted:function() {
				this.init();
			},
			methods:{
				init() {
					// 获取配置
					$.getJSON('../../resource/config.json',function(res){
						main.api_prefix = res.api_prefix;
						main.api_key = res.api_key;
						main.app_version = res.app_version;
						main.app_version_check_url = res.app_version_check_url;
					});
					document.addEventListener('plusready',function () {
						plus.navigator.setFullscreen(true);
						plus.key.addEventListener('backbutton', function() {
							plus.webview.currentWebview().close();
							return false;
						}, false);
						// 获取信息
						main.userInfo = {
							user_id:plus.storage.getItem("user_id"),
							user_name:plus.storage.getItem("user_name"),
							nick_name:plus.storage.getItem("nick_name"),
							email:plus.storage.getItem("email"),
							user_head:plus.storage.getItem("user_head"),
						}
					});
				},
				closeView() {
					plus.webview.currentWebview().close();
				},
				doSearch() {
					if(this.searchText != ""){
						this.searchResult = [{
							user_id:1,
							user_name:"test",
							user_head:"../../resource/img/0.jpg",
							nick_name:"testUserForSearch"
						},{
							user_id:1,
							user_name:"test",
							user_head:"../../resource/img/0.jpg",
							nick_name:"testUserForSearch"
						},{
							user_id:1,
							user_name:"test",
							user_head:"../../resource/img/0.jpg",
							nick_name:"testUserForSearch"
						},{
							user_id:1,
							user_name:"test",
							user_head:"../../resource/img/0.jpg",
							nick_name:"testUserForSearch"
						},];
						if(this.searchText == "empty"){
							this.searchResult = "";
						}
						if(this.searchResult == ""){
							$(".data-empty").show();
						}else{
							$(".data-empty").hide();
						}
						$(".search-result-list").show();
					}else{
						this.$toast({message:"请输入搜索内容",position:'bottom',duration: 1500})
					}
				},
				addApply(id) {
					alert(id)
				}
			}
		})
	</script>
</html>
